﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Model;
using System.Data;

namespace FubiManger.Controls
{
    ////ToolboxItem用于控制是否添加自定义控件到工具箱，true添加，false不添加
    //[System.ComponentModel.ToolboxItem(true)]
    partial class Regioncontrol : Smobiler.Core.Controls.MobileUserControl
    {
        public Regioncontrol() : base()
        {
            //This call is required by the SmobilerUserControl.
            InitializeComponent();
        }
        public string level = "1";
        private string partid = "";
        /// <summary>
        /// 省
        /// </summary>
        public string prov { get; set; }
        /// <summary>
        /// 区
        /// </summary>
        public string area { get; set; }
        /// <summary>
        /// 市
        /// </summary>
        public string city { get; set; }
        List<ms_region> rglist = new List<ms_region>();
        private void btnclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 省
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnpvo_Press(object sender, EventArgs e)
        {
            btncity.Visible = false;
            btncounty.Visible = false;
            btnpvo.ForeColor = System.Drawing.Color.FromArgb(255, 77, 74);
            rglist = regionDal.Querybylevel("1");
            Getview();
        }
        /// <summary>
        /// 市
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btncity_Press(object sender, EventArgs e)
        {
            btncity.ForeColor = System.Drawing.Color.FromArgb(255, 77, 74);
            btnpvo.ForeColor = System.Drawing.Color.DimGray;
            btncounty.Visible = false;
            rglist = regionDal.Querybyprid(partid);
            Getview();
        }
        /// <summary>
        /// 城市列表
        /// </summary>
        private void Getview()
        {
            DataTable table = new DataTable();
            table.Columns.Add("cityname");
            table.Columns.Add("level");
            table.Columns.Add("id");

            for (int i = 0; i < rglist.Count; i++)
            {
                table.Rows.Add(rglist[i].name, rglist[i].level, rglist[i].id);
            }
            lvregion.DataSource = table;
            lvregion.DataBind();
        }
        /// <summary>
        /// 获取下一级地址列表
        /// </summary>
        /// <param name="lv"></param>
        /// <param name="prid"></param>
        public void Getcity(string lv, string prid, string name)
        {
            level = lv;
            partid = prid;
            switch (lv)
            {
                case "1":
                    btnpvo.Text = name;
                    btnpvo.ForeColor = System.Drawing.Color.FromArgb(255, 77, 74);
                    btncity.Visible = true;
                    btncity.Text = "请选择";
                    btncounty.Visible = false;
                    break;
                case "2":
                    btncity.Text = name;

                    btncity.ForeColor = System.Drawing.Color.FromArgb(255, 77, 74);
                    btnpvo.ForeColor = System.Drawing.Color.DimGray;
                    btncounty.ForeColor = System.Drawing.Color.DimGray;
                    btncounty.Visible = true;
                    btncounty.Text = "请选择";
                    break;
                case "3":
                    btncounty.Text = name;
                    //btncounty.Visible = true;
                    //btncounty.ForeColor = System.Drawing.Color.FromArgb(255, 77, 74);
                    //btnpvo.ForeColor= System.Drawing.Color.DimGray;
                    //btncity.ForeColor = System.Drawing.Color.DimGray;
                    city = btncity.Text;
                    prov = btnpvo.Text;
                    area = btncounty.Text;
                    this.Close();
                    break;
            }
            rglist = regionDal.Querybyprid(prid);
            Getview();
        }

        private void button1_Press(object sender, EventArgs e)
        {

        }
    }
}